﻿Ext.extend(demo.module,{
    init: function(){
    var form = new Ext.FormPanel({
        labelWidth: 150,       
        frame:true,       
        bodyStyle:'padding:10px 10px 0',
        width: 350,
        defaults: {width: 230},
        defaultType: 'textfield',
        items: [
            {
                fieldLabel: 'gmail 帐户名',
                name: 'mailaccount',
                allowBlank:false
            },{
                fieldLabel: 'gmail 密码',
                inputType:'password',
                name: 'mailpass',
                allowBlank:false
            },{
                fieldLabel: '邮主题前缀',
                name: 'presubject',
                allowBlank:false
            }
            ,{
                fieldLabel: '接收邮箱',
                xtype:'textarea',
                width:500,
                height:100,
                name: 'mailto',
                allowBlank:false
            },
            {
              xtype:'fieldset',
              bodyStyle:'padding:10px',
              width:655,
              height:100,
              html:[
                '<font color=red>说明：<br/></font>',
                '1. 需要配置发送邮件的服务器（只支持gmail）<br/>',
                '2. 配置发送邮件的主题前缀（例如：[inquiry]）<br/>',
                '3. to 为接收的邮件地址，多个邮件请用英文的"," 逗号分开！'
              ].join("")
            }           
        ],
        buttons: [{
            text: 'Save',
            handler:function(){
            var form=this.ownerCt;
            if(form.getForm().isValid())
            {
	            form.getForm().submit({url:'savemail', waitMsg:'save password...',
	            success:function(form, action){
	              Ext.MessageBox.alert('提示信息',action.result.info);       
	            },
	            failure:function(form, action){
	              Ext.MessageBox.alert('错误信息',action.result.info); 
	            }            
	            });
            }
           }
        }]
     });    
	 this.main.add(form);
     this.main.doLayout(); 
 	 Ext.Ajax.request({ 
		     method:'POST', 
		     url:'mail', 	
		     params:{_time:(new Date()).getTime()},
		     success : function(response, request) {
			     var data=Ext.decode(response.responseText);				    	     
			     var b=form.getForm();			   
			     b.findField("mailaccount").setValue(data.mailaccount);
			     b.findField("mailpass").setValue(data.mailpass);
			     b.findField("presubject").setValue(data.presubject);
			     b.findField("mailto").setValue(data.mailto);
		     }, 
		     failure : function(response, request) { 		     
			     Ext.MessageBox.alert('错误信息', "服务器异常");
		     } 
	  });     
     
    }
});